package org.jeecg.modules.system.controller;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.system.dto.DashboardStatsDTO;
import org.jeecg.modules.system.service.IDashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 首页数据统计控制器
 */
@Slf4j
@RestController
@RequestMapping("/sys/dashboard")
public class DashboardController {

    @Autowired
    private IDashboardService dashboardService;

    /**
     * 获取首页统计概览数据
     */
    @GetMapping("/stats")
    public Result<DashboardStatsDTO> getDashboardStats() {
        try {
            log.info("Fetching dashboard statistics...");
            DashboardStatsDTO stats = dashboardService.getDashboardStats();
            log.info("Successfully fetched dashboard statistics");
            return Result.OK(stats);
        } catch (Exception e) {
            log.error("Error fetching dashboard statistics: ", e);
            return Result.error("获取仪表盘数据失败: " + e.getMessage());
        }
    }
}
